package com.wyx.springvueadmin.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wyx.springvueadmin.entity.PageBean;
import com.wyx.springvueadmin.entity.User;
import com.wyx.springvueadmin.mapper.userMapper;
import com.wyx.springvueadmin.service.userService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class userServiceImpl implements userService {

    @Autowired
    private userMapper usermapper;

    @Override
    public User findById(Integer id) {
        User user=usermapper.finById(id);
        return user;
    }

    @Override
    public List<User> findAll() {
        List<User> list=usermapper.findAll();
        return list;
    }

    @Override
    public void save(User user) {
        usermapper.save(user);
    }

    @Override
    public void delete(Integer id) {
        usermapper.delete(id);
    }

    @Override
    public void change(User user) {
        usermapper.change(user);
    }

    @Override
    public PageBean page(Integer page,Integer pageSize){
        PageHelper.startPage(page,pageSize);
        List<User> list=usermapper.page();
        Page<User> p=(Page<User>) list;
        PageBean pageBean=new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }

    @Override
    public List<User> selectBySex(Integer sex) {
        List<User> list=usermapper.selectBySex(sex);
        return list;
    }
}
